/*------------------------------------------------------------------------------

    File    :   MPEGA.h

    Author  :   Stéphane TAVENARD

    $VER:   MPEGA.h  2.0  (21/06/1998)

    (C) Copyright 1997-1998 Stéphane TAVENARD
        All Rights Reserved

    #Rev|   Date   |                      Comment
    ----|----------|--------------------------------------------------------
    0   |25/10/1997| Initial revision                                     ST
    1   |21/06/1998| Added MPEGA_scale                                    ST

    ------------------------------------------------------------------------

    MPEGA decoder library definitions

------------------------------------------------------------------------------*/
#define MPEGA_VERSION  2        /* #1 */

MODULE  'utility/hooks'

/* Controls for decoding */
/* Qualities */

#define MPEGA_QUALITY_LOW     0
#define MPEGA_QUALITY_MEDIUM  1
#define MPEGA_QUALITY_HIGH    2

/*
   Bitstream Hook function is called like (SAS/C syntax):


   ULONG __saveds __asm HookFunc( register __a0 struct Hook  *hook,
                                  register __a2 APTR          handle,
                                  register __a1 MPEGA_ACCESS *access );

   MPEGA_ACCESS struct specify bitstream access function & parameters

   access->func == MPEGA_BSFUNC_OPEN
      open the bitstream
      access->data.open.buffer_size is the i/o block size your read function can use
      access->data.open.stream_size is the total size of the current stream
                                    (in bytes, set it to 0 if unknown)
      return your file handle (or NULL if failed)
   access->func == MPEGA_BSFUNC_CLOSE
      close the bitstream
      return 0 if ok
   access->func == MPEGA_BSFUNC_READ
      read bytes from bitstream.
      access->data.read.buffer is the destination buffer.
      access->data.read.num_bytes is the number of bytes requested for read.
      return # of bytes read or 0 if EOF.
   access->func == MPEGA_BSFUNC_SEEK
      seek into the bitstream
      access->data.seek.abs_byte_seek_pos is the absolute byte position to reach.
      return 0 if ok
*/

#define MPEGA_BSFUNC_OPEN   0
#define MPEGA_BSFUNC_CLOSE  1
#define MPEGA_BSFUNC_READ   2
#define MPEGA_BSFUNC_SEEK   3

OBJECT MPEGA_ACCESS                                     /* Decoding output settings */
        func:LONG,                                   /* MPEGA_BSFUNC_xxx */
        OBJECT data
                OBJECT open
                        stream_name:PTR TO UBYTE,    /* in */
                        buffer_size:LONG,            /* in */
                        stream_size:LONG             /* out */
                ENDOBJECT,
                OBJECT read
                        buffer:VOID,    /* in/out */
                        num_bytes:LONG         /* in */
                ENDOBJECT,
                OBJECT seek
                        byte_seek_pos:LONG     /* out */
                ENDOBJECT
        ENDOBJECT

OBJECT MPEGA_OUTPUT          /* Decoding layer settings */
        freq_div:WORD,    /* 1, 2 or 4 */
        quality:WORD,     /* 0 (low) .. 2 (high) */
        freq_max:LONG     /* for automatic freq_div (if mono_freq_div == 0) */

OBJECT MPEGA_LAYER                /* Full control structure of MPEG Audio decoding */
        force_mono:WORD,        /* 1 to decode stereo stream in mono, 0 otherwise */
        mono:MPEGA_OUTPUT,      /* mono settings */
        stereo:MPEGA_OUTPUT     /* stereo settings */

OBJECT MPEGA_CTRL                    /* MPEG Audio modes */
        bs_access:PTR TO Hook,      /* NULL for default access (file I/O) or give your own bitstream access */
        layer_1_2:MPEGA_LAYER,      /* Layer I & II settings */
        layer_3:MPEGA_LAYER,        /* Layer III settings */
        check_mpeg:WORD,            /* 1 to check for mpeg audio validity at start of stream, 0 otherwise */
        stream_buffer_size:LONG     /* size of bitstream buffer in bytes (0 -> default size) */

#define MPEGA_MODE_STEREO    0
#define MPEGA_MODE_J_STEREO  1
#define MPEGA_MODE_DUAL      2
#define MPEGA_MODE_MONO      3

OBJECT MPEGA_STREAM
        norm:WORD,             /* 1 or 2 */
        layer:WORD,            /* 1..3 */
        mode:WORD,             /* 0..3  (MPEGA_MODE_xxx) */
        bitrate:WORD,          /* in kbps */
        frequency:LONG,        /* in Hz */
        channels:WORD,         /* 1 or 2 */
        ms_duration:ULONG,     /* stream duration in ms */
        private_bit:WORD,      /* 0 or 1 */
        copyright:WORD,        /* 0 or 1 */
        original:WORD,         /* 0 or 1 */
        dec_channels:WORD,     /* decoded channels 1 or 2 */
        dec_quality:WORD,      /* decoding quality 0..2 */
        dec_frequency:LONG,    /* decoding frequency in Hz */
        handle:VOID

#define MPEGA_MAX_CHANNELS  2           // Max channels
#define MPEGA_PCM_SIZE      1152        // Max samples per frame

/* Error codes */

#define MPEGA_ERR_NONE      0
#define MPEGA_ERR_BASE      0
#define MPEGA_ERR_EOF       (MPEGA_ERR_BASE-1)
#define MPEGA_ERR_BADFRAME  (MPEGA_ERR_BASE-2)
#define MPEGA_ERR_MEM       (MPEGA_ERR_BASE-3)
#define MPEGA_ERR_NO_SYNC   (MPEGA_ERR_BASE-4)
#define MPEGA_ERR_BADVALUE  (MPEGA_ERR_BASE-5)  /* #1 */

